package com.heking.qlyopensdkapp.ui;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.heking.qlyopensdkapp.PageHelper;
import com.zhoug.common.utils.bundle.BundleWrap;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @Author: zhoug
 * @Date: 2024-11-05
 * @Description:
 */
public abstract class BaseActivity extends AppCompatActivity {
    protected PageHelper mPageHelper;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        beforeLayout(savedInstanceState);
        setContentView(getLayoutResID());
        findViews();
        mPageHelper = new PageHelper(this);
        addListener();
        initView();
        onCreateEnd(savedInstanceState);

    }

    public abstract void beforeLayout(@Nullable Bundle savedInstanceState);

    protected abstract @LayoutRes int getLayoutResID();

    protected abstract void findViews();

    protected abstract void addListener();

    protected abstract void initView();

    protected abstract void onCreateEnd(@Nullable Bundle savedInstanceState);

    protected BaseActivity getActivity() {
        return this;
    }

    protected void toast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    protected void logAndToastE(String tag, String msg) {
        Log.e(tag, msg);
        toast(msg);
    }

    protected void logAndToastD(String tag, String msg) {
        Log.d(tag, msg);
        toast(msg);
    }

    /**
     * 获取Intent中的数据包装对象
     * Bundle包装类,异常捕获
     * 本地拒绝服务攻击:应用程序在编写过程中没有对getXXXExtra()这类方法调
     * 用进行异常的捕获，攻击者可以通过发送空数据、异常数据或畸形数据使程序崩溃，从而造成拒绝服务攻击
     *
     * @Author 35574
     * @Date 2021/10/25
     * @Description
     */
    public BundleWrap getIntentExtras() {
        Bundle extras = getIntent().getExtras();
        if (null != extras) {
            return BundleWrap.with(extras);
        }
        return null;
    }
}
